//
//  PlayingCard.m
//  MemoPocker
//
//  Created by Jose Luis Ferreyra on 18/02/13.
//  Copyright (c) 2013 Dharma. All rights reserved.
//

#import "PlayingCard.h"


#define macro

@implementation PlayingCard

+ (NSArray *) validSuits
{
    return @[@"♠",@"♣",@"♥",@"♦"];
}

+ (NSArray *) rankStrings
{
    return @[@"A", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", @"10", @"J", @"Q", @"K"];
}

+ (NSUInteger)maxRank
{
    return [self rankStrings].count-1;
}

- (void)setRank:(NSUInteger)rank
{
    if (rank <= [PlayingCard maxRank])
    {
        _rank=rank;
    }
}

- (NSString *)contents
{
    NSArray *rankStrings = [PlayingCard rankStrings];
    return [rankStrings[self.rank] stringByAppendingString:self.suit];
}

@synthesize suit = _suit;

- (void) setSuit:(NSString *) suit{
    if ([[PlayingCard validSuits] containsObject:suit])
    {
        _suit = suit;
    }
}

- (NSString *)suit{
    return _suit ? _suit : @"?";
}

- (int)match: (NSArray *)otherCards{
    int score = 0;
    if ([otherCards count]>0)
        for (id card in otherCards) {
            if ([card isKindOfClass:[PlayingCard class]]){
                PlayingCard *otherCard = (PlayingCard *)card;
                if (otherCard.rank == self.rank)
                {
                    score=4;
                }
                else if ([otherCard.suit isEqualToString: self.suit])
                {
                    score=1;
                }
            }
        }
    return score;
}


@end
